﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTAshReviewService : ServiceHandle, IRPTAshReview
    {
        #region IRPTAshReview Members

        public OperationResult<List<tb_RPT_AshReview>> GetAllAshReview()
        {
            OperationResult<List<tb_RPT_AshReview>> result = new OperationResult<List<tb_RPT_AshReview>>();
            List<tb_RPT_AshReview> list = new List<tb_RPT_AshReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllAshReview();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_AshReview>> GetAshReviewByContition(string strSequence, string strProjectName
                                                                            , string strASHManufacturer, string strOutSequence
                                                                            , string strInDate, string strTestDate)
        {
            OperationResult<List<tb_RPT_AshReview>> result = new OperationResult<List<tb_RPT_AshReview>>();
            List<tb_RPT_AshReview> list = new List<tb_RPT_AshReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAshReviewByContition(strSequence, strProjectName, strASHManufacturer, strOutSequence, strInDate, strTestDate);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_AshReview>> GetAshReviewByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_AshReview>> result = new OperationResult<List<tb_RPT_AshReview>>();
            List<tb_RPT_AshReview> list = new List<tb_RPT_AshReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAshReviewByProjectName(strProjectName);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_AshReview> GetAshReviewById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_AshReview> result = new OperationResult<tb_RPT_AshReview>();
            tb_RPT_AshReview ashReview;
            try
            {
                ashReview = dataContext.GetAshReviewById(id);
                if (ashReview == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = ashReview;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_AshReview> CreateAshReview(tb_RPT_AshReview entity)
        {
            OperationResult<tb_RPT_AshReview> result = new OperationResult<tb_RPT_AshReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateAshReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_AshReview> ModifyAshReview(tb_RPT_AshReview entity)
        {
            OperationResult<tb_RPT_AshReview> result = new OperationResult<tb_RPT_AshReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyAshReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_AshReview> DeleteAshReview(tb_RPT_AshReview entity)
        {
            OperationResult<tb_RPT_AshReview> result = new OperationResult<tb_RPT_AshReview>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteAshReview(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
